package au.chao.message.builder;

import au.chao.exception.JIMException;
import au.chao.message.Message;
import au.chao.message.MessageHeader;
import au.chao.message.TextMessage;
import au.chao.message.TextMessageContent;
import au.chao.message.TextMessageHeader;

public class TextMessageBuilder extends MessageBuilder {

	Message msg = null;

	public TextMessageBuilder() {
		msg = new TextMessage();
	}

	@Override
	public void buildContent(Object obj) {
		if (obj instanceof String) {
			msg.setContent(new TextMessageContent(obj.toString()));
		} else {
			throw new JIMException("Can not build text message content using:" + obj.toString());
		}
	}

	@Override
	public void buildHeader(int fromUserId, int toUserId) {
		MessageHeader header = new TextMessageHeader();
		header.setFromUserId(fromUserId);
		header.setToUserId(toUserId);
		msg.setHeader(header);
	}

	@Override
	public Message getMessage() {
		return msg;
	}

}
